package com.cefa.finance.dao;

import com.cefa.finance.model.Account;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@SuppressWarnings("ALL")
@Repository
public interface AccountRepository extends CrudRepository<Account, Long> {

    @Query(value = "select * from cefa_finance_account where user_account = ?1 and password=?2", nativeQuery = true)
    Account findByAccountAndPassword(String account, String password);

    @Query(value = "select phone from cefa_finance_account", nativeQuery = true)
    List<String> findPhones();

    @Query(value = "select * from cefa_finance_account where user_account = ?1", nativeQuery = true)
    Account findByUserAccount(String userAccount);

    @Query(value = "select * from cefa_finance_account where user_account = ?1 and super_user= ?2", nativeQuery = true)
    Account findByUserAccountAndSuperUser(String userAccount, Boolean superUser);

    @Query(value = "select * from cefa_finance_account where phone = ?1", nativeQuery = true)
    Account findByPhone(String phone);

    @Query(value = "select * from cefa_finance_account where super_user is not true and address is null and prikey is null", nativeQuery = true)
    List<Account> findNoPrivateKeyAccount();
}
